
const yt = {}

// 模拟应该数据库
const db = {
    '1': {
        title: '吃饭了吗',
        // 下级
        lower_level: ['2', '3']
    },
    '2': {
        title: '吃了',
        lower_level: ['4']
    },
    '3': {
        title: '没吃',
        lower_level: []
    },
    '4': {
        title: '吃什么',
        lower_level: ['5', '6']
    },
    '5': {
        title: '米粉',
        lower_level: ['7']
    },
    '6': {
        title: '米饭',
        lower_level: ['7']
    },
    '7': {
        title: '吃几碗',
        lower_level: ['8', '9', '10']
    },
    '8': {
        title: '一碗',
        lower_level: []
    },
    '9': {
        title: '两碗',
        lower_level: []
    },
    '10': {
        title: '三碗',
        lower_level: []
    }
}


// 找到父级下的所有子级
const findLowerLevel = function (id) {
    let lower_level = db[id].lower_level;
    let arr = [];
    for (let i = 0; i < lower_level.length; i++) {
        let item = db[lower_level[i]];
        item.id = lower_level[i];
        arr.push(item);
    }
    return arr;
}


// 模拟请求
yt.request = function (id) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(findLowerLevel(id));
        }, 300);
    })
}

export default yt